package com.liu.mhl.Server;

import com.liu.mhl.dao.DiningTableDao;
import com.liu.mhl.domain.DiningTable;


import java.util.List;

public class DiningTableServer {
    private DiningTableDao diningTableDao =   new DiningTableDao();

    public List<DiningTable> list () {
        return diningTableDao.queryMulti("select id ,state  from diningTable where id > ?", DiningTable.class);
    }
    //根据id 查询餐桌对象
    //如果返回null,则餐桌对象不存在
   public DiningTable getDiningTableById (int id) {
        return diningTableDao.querySingle("select * from diningTable where id =?",DiningTable.class,id);
   }
   //如果餐桌预订，则对餐桌状态进行更新
    public boolean orderDiningTable(int id , String orderName ,String orderTel ) {
        int update = diningTableDao.update("update diningTable set state='已经预订',orderName = ? , orderTel= ? , where id = ?", orderName, orderTel , id);
        return update > 0;
    }
    //需要提供一个餐桌更新状态的方法
    public boolean updateDiningTableState(int id , String state) {
        int update = diningTableDao.update("update diningTable set state = ? where id = ?", state, id);
        return update > 0;
    }

    //提供一个方法将指定餐桌状态置为空
    public boolean updateDiningTableOrderState(int id , String state) {
        int update = diningTableDao.update("update diningTable set state = ?,orderName = ?,orderTel=? where id = ?", state, id);
        return update > 0;
    }
}
